package yxy.game.pm2.command.plainsarena;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.PlainsArenaMessage;
import yxy.game.pm2.module.plainsarena.PlainsArenaHandle;

import java.util.Date;

/** 中原擂台 中原擂台选手信息 */
@MessageType(proto = Command.PlainsArenaPlayerInfo, classtype = PlainsArenaMessage.PlainsArenaPlayerInfoRequest.class)
public class CMD_PlainsArenaPlayerInfo extends Command<PlainsArenaMessage.PlainsArenaPlayerInfoRequest> {

	@Override
	public void execute(MessageSource messageSource, PlainsArenaMessage.PlainsArenaPlayerInfoRequest request) {
		Date date = new Date();

		String playerCode = messageSource.getTag();
		int rank = request.getRank();
		int level = request.getLevel();

		PlainsArenaMessage.PlainsArenaPlayerInfoResponse.Builder response = PlainsArenaMessage.PlainsArenaPlayerInfoResponse.newBuilder();

		Result result = new PlainsArenaHandle().rankInfo(playerCode, rank, level, response);

		send(messageSource, response, result);

		Date date1 = new Date();
		System.out.println("CMD_PlainsArenaPlayerInfo:"+(date1.getTime()-date.getTime()));

	}

	private void send(MessageSource messageSource, PlainsArenaMessage.PlainsArenaPlayerInfoResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}